﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;

public partial class Pages_StudentPages_StudentUpload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Role"] != null && "Student".Equals(Session["Role"]) == false)
        {
            Response.Redirect("~/Pages/HomePage/Home.aspx");
        }
        string id = Request.QueryString["id"];
    }

    protected void btnUpload_Click(object sender, EventArgs e)
    {
        if (fileDesignImg.HasFile)
        {
            Design d = new Design();
            StudentBUS st = new StudentBUS();
            d.Name = txtDesignName.Text;
            d.PostDate = DateTime.Now.Date.ToString();
            d.Description = txtDescription.Text;
            d.Quotation = txtQuotation.Text;
            d.St.Id = Convert.ToInt16(Session["Id"]);
            d.Com.ComId = Convert.ToInt16(Request.QueryString["id"]);
            string fileName = Path.GetFileName(fileDesignImg.PostedFile.FileName);
            string extension = Path.GetExtension(fileName);
            //fileCompImage.PostedFile.SaveAs(Server.MapPath("~/Images/Competition/") + fileName);
            d.DesignImage = extension;
            DataSet ds = st.insertDesign(d);
            if (ds.Tables[0].Rows.Count > 0)
            {
                int compId = Convert.ToInt16(ds.Tables[0].Rows[0]["designImg"]);
                string saveFile = compId + extension;
                fileDesignImg.PostedFile.SaveAs(Server.MapPath("~/Images/Design/") + saveFile);
                Response.Redirect("~/Pages/HomePage/Success.aspx");
            }
        }
    }
}